out vec3 LightIntensity;
out vec3 Position;
out vec3 Normal;

uniform vec4 LightPosition; // Light position in eye coords.
uniform vec3 Kd; // Diffuse reflectivity
uniform vec3 Ld; // Light source intensity

uniform float Time;

uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ProjectionMatrix;

void main()
{
	const float PI = 3.14159265358979323846264;
	const float rectaEstaticaA = 9.0;
	const float rectaEstaticaB = 0.0;
	const float puntoMedio = (rectaEstaticaA - rectaEstaticaB) / 2;
	const float distanciaTotal = rectaEstaticaA - puntoMedio;

	// Convert normal and position to eye coords
	vec3 tnorm = normalize( NormalMatrix * gl_Normal);
	vec4 eyeCoords = ViewMatrix * ModelMatrix * gl_Vertex;
	vec3 s = normalize(vec3(LightPosition - eyeCoords));
	
	// The diffuse shading equation
	vec4 light_pos = ViewMatrix * LightPosition;
	LightIntensity = 0.8 * Ld * Kd * max( dot( s, tnorm ), 0.0 ) + 0.10;

	float variacion = cos(Time * PI)*sin((gl_Vertex.y + 0.5) * (gl_Vertex.x + 0.5) * PI / 10 );
	if (gl_Vertex.y < rectaEstaticaB || gl_Vertex.y > rectaEstaticaA) variacion = 0.0;
	//variacion = variacion*( 1 - abs((gl_Vertex.y - puntoMedio)/distanciaTotal));

	vec4 moveVector = vec4( gl_Vertex );
	moveVector.z = moveVector.z + variacion*0.5;

	// Convert position to clip coordinates and pass along
	gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * moveVector;
}